package com.hzqy.service.commons;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.hzqy.service.hotel.HotelServiceBean;
import com.hzqy.service.itf.YxtItfServiceBean;
import com.hzqy.web.filter.OrgModelFilter;

public abstract class OrgModelFilterService {
	private static final Log LOG = LogFactory.getLog(OrgModelFilter.class);
	
	/**
	 * session中没有PmsOrgVo对象
	 */
	public static final int SESSION_PMS_ORG_IS_EMPTY = 1;
	
	/**
	 * 无法找到业务账号对应的PmsOrgVo对象
	 */
	public static final int PMS_ORG_OF_SERVERID_NOT_FOUND = 2;
	
	/**
	 * 找到业务账号对应的PmsOrgVo对象
	 */
	public static final int PMS_ORG_OF_SERVERID_FOUND = 3;
	
	/**
	 * 无法获取模版信息(路径)
	 */
	public static final int MODEL_NOT_FOUND = 4;
	
	/**
	 * 用户组织对应的模版获取成功
	 */
	public static final int USER_PMS_ORG_MODEL_FOUND = 5;
	
	/**
	 * 用户组织对应的模版获取失败
	 */
	public static final int USER_PMS_ORG_MODEL_NOT_FOUND = 6;
	
	public static final OrgModelFilterService getInstance(String uri, HttpSession session){
		WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
		OrgModelFilterService omfs = null;
		if(uri.endsWith("index/index_school.jsp")||uri.indexOf("/school_hd/") > -1){
			omfs = (YxtItfServiceBean)webApplicationContext.getBean("yxtItfServiceBean");
		}else if(uri.indexOf("/hotel/") > -1){
			omfs = (HotelServiceBean)webApplicationContext.getBean("hotelServiceBean");
		}
		
		if(omfs == null){
			LOG.debug("无效的uri: " + uri + ", 无法获取对应的业务对象类, 默认使用校园业务类。");
			omfs = (YxtItfServiceBean)webApplicationContext.getBean("yxtItfServiceBean");
		}
		
		return omfs;
	}
	
	/**
	 * @return 需要返回一个绑定业务账号的分类id
	 */
	public abstract int getCatalogidOfServerid();
	
	/**
	 * 
	 * 事件处理方法，所有事件可查看上面所有静态属性，Event可能是其中任意一个值，方法中处理相应的事件
	 * 方法调用可以看com.hzqy.web.filter.OrgModelFilter
	 * 
	 * @param Event 事件
	 * @param param :
	 * 	{
	 * 		"request" : HttpServletRequest, 
	 * 		"response" : HttpServletResponse, 
	 * 		"chain" : FilterChain,
	 * 		"filter" : OrgModelFilter
	 *  }
	 */
	public abstract void handleEvent(int Event, Map<String, Object> param);
	
	
	
	
}
